package j_Inst;

import mips.Decoder;
import mips.PC;
import mips.Register;

public class Jal {
	public static void jal(int targetedAddress){
		System.out.println("PC value now is : " +Decoder.toBinary(PC.pc)); 
		System.out.println("PC value :"+ Decoder.toBinary(PC.pc)+" sent to The Instruction memory to read address..");
		System.out.println("Instuction memory sending Instruction [31:26] to CONTROL,Instruction[31:26] having the value '000011'");
		System.out.println("Instuction memory sending Instruction[25:0] to Shift left by 2");
		int shiftedAddress = targetedAddress << 2;
		PC.fourAdder(PC.pc);
		Register.registers[31] = PC.pc;
		PC.pc = shiftedAddress;
		System.out.println("CONTROL sends Jump of 01 to mux");
		System.out.println("mux choose the Pc value of the jump ");
    System.out.println("The new Pc value is:" + Decoder.toBinary(PC.pc));  
		System.out.println("CONTROL sends RegDst of 10 to mux");
		System.out.println("mux choose $ra to Registers @ write Register");
		System.out.println("Register to write to is '$ra'");
		System.out.println("CONTROL sends MemToReg of 10 to mux");
		System.out.println("CONTROL sends RegWrite of 1 to Registers");
		System.out.println("Writing the value of PC in $ra.....");
		System.out.println("The value of the $ra: " + Register.registers[31]);
    System.out.println("------------------------------------");
	}
}
